package com.nari.kmd_dataservice.schedule;

import com.nari.kmd_dataservice.service.AutoServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName: AutoTask
 * @Description: 自动任务
 * @Author: zhangnaijiang
 * @Date: 2022/02/17 12:34
 * @Version 1.0.0
 */
@Slf4j
@Component
@EnableScheduling   // 1.开启定时任务
@EnableAsync        // 2.开启多线程
public class AutoTask {
    @Resource
    private AutoServerService autoServerService;

    @Async
//    @Scheduled(fixedDelay = 1000)  //间隔1秒
    @Scheduled(cron = "1 0/1 * * * ?") //每分钟
    public void autoTargetResponse() {
        log.info("定时发布事件任务开始");
//        autoServerService.autoCreateEvent();
        autoServerService.autoTargetResponse();
        log.info("定时发布事件任务结束");
    }

    @Async
    @Scheduled(cron = "0 0/5 * * * ?") //每分钟
    public void autoCheckResponseEvent() {
        log.info("定时检查事件任务开始");
        autoServerService.autoCheckResponseEvent();
        log.info("定时检查事件任务结束");
    }
}
